package com.cnswhy.cloud.security.starter.handler;

import com.cnswhy.cloud.common.core.entity.CnswhyResponse;
import com.cnswhy.cloud.common.core.utils.CnswhyUtil;
import org.springframework.http.MediaType;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CnswhyAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        CnswhyResponse cnswhyResponse = new CnswhyResponse();
        CnswhyUtil.makeJsonResponse(httpServletResponse, HttpServletResponse.SC_FORBIDDEN,cnswhyResponse.message("没有权限访问该资源"));

    }
}
